<?php

/**
 * This is the model class for table "tb_servico".
 *
 * The followings are the available columns in table 'tb_servico':
 * @property integer $ID_SERVICO
 * @property integer $AJUDANTE_SERVICO
 * @property integer $EMPILHADEIRA_SERVICO
 * @property string $FRETE_SERVICO
 * @property string $MATERIAIS_SERVICO
 *
 * The followings are the available model relations:
 * @property TbMercadoria[] $tbMercadorias
 */
class Servico extends CActiveRecord
{
	/**
	 * Returns the static model of the specified AR class.
	 * @param string $className active record class name.
	 * @return Servico the static model class
	 */
	public static function model($className=__CLASS__)
	{
		return parent::model($className);
	}

	/**
	 * @return string the associated database table name
	 */
	public function tableName()
	{
		return 'tb_servico';
	}

	/**
	 * @return array validation rules for model attributes.
	 */
	public function rules()
	{
		// NOTE: you should only define rules for those attributes that
		// will receive user inputs.
		return array(
			array('AJUDANTE_SERVICO, EMPILHADEIRA_SERVICO', 'numerical', 'integerOnly'=>true),
			array('FRETE_SERVICO', 'length', 'max'=>30),
			array('MATERIAIS_SERVICO', 'length', 'max'=>300),
			// The following rule is used by search().
			// Please remove those attributes that should not be searched.
			array('ID_SERVICO, AJUDANTE_SERVICO, EMPILHADEIRA_SERVICO, FRETE_SERVICO, MATERIAIS_SERVICO', 'safe', 'on'=>'search'),
		);
	}

	/**
	 * @return array relational rules.
	 */
	public function relations()
	{
		// NOTE: you may need to adjust the relation name and the related
		// class name for the relations automatically generated below.
		return array(
			'tbMercadorias' => array(self::HAS_MANY, 'TbMercadoria', 'TB_SERVICO_ID_SERVICO'),
		);
	}

	/**
	 * @return array customized attribute labels (name=>label)
	 */
	public function attributeLabels()
	{
		return array(
			'ID_SERVICO' => 'Id Servico',
			'AJUDANTE_SERVICO' => 'Ajudante Servico',
			'EMPILHADEIRA_SERVICO' => 'Empilhadeira Servico',
			'FRETE_SERVICO' => 'Frete Servico',
			'MATERIAIS_SERVICO' => 'Materiais Servico',
		);
	}

	/**
	 * Retrieves a list of models based on the current search/filter conditions.
	 * @return CActiveDataProvider the data provider that can return the models based on the search/filter conditions.
	 */
	public function search()
	{
		// Warning: Please modify the following code to remove attributes that
		// should not be searched.

		$criteria=new CDbCriteria;

		$criteria->compare('ID_SERVICO',$this->ID_SERVICO);
		$criteria->compare('AJUDANTE_SERVICO',$this->AJUDANTE_SERVICO);
		$criteria->compare('EMPILHADEIRA_SERVICO',$this->EMPILHADEIRA_SERVICO);
		$criteria->compare('FRETE_SERVICO',$this->FRETE_SERVICO,true);
		$criteria->compare('MATERIAIS_SERVICO',$this->MATERIAIS_SERVICO,true);

		return new CActiveDataProvider($this, array(
			'criteria'=>$criteria,
		));
	}
}